// -------------------------------------------------------------------------
//    @FileName			:    {Filename}
//    @Author           :    GaoYi
//    @Date             :    2017-09-27
//    @Module           :   {Filename}
//
// -------------------------------------------------------------------------

#pragma once
#include <cstring>
#include <cerrno>
#include <cstdio>
#include <csignal>
#include <cstdint>
#include <iostream>
#include <map>
#include <vector>
#include <functional>
#include <memory>
#include <list>
#include <vector>
#include <cassert>

#if NF_PLATFORM == NF_PLATFORM_WIN
#include <WinSock2.h>
#include <windows.h>
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_LINUX || NF_PLATFORM == NF_PLATFORM_ANDROID

#if NF_PLATFORM == NF_PLATFORM_APPLE

#include <libkern/OSByteOrder.h>

#endif

#include <netinet/in.h>

#ifdef _XOPEN_SOURCE_EXTENDED
#  include <arpa/inet.h>
# endif

#include <sys/socket.h>
#include <unistd.h>

#endif

#include "NFComm/NFPluginModule/NFPlatform.h"


struct  NFIMsgHead
{
	virtual int GetHeadLength() = 0;

	virtual int EnCode(char* strData) = 0;
	virtual int DeCode(const char* strData) = 0;

	virtual uint32_t GetMsgID() const = 0;
	virtual void SetMsgID(uint32_t nMsgID) = 0;

	virtual uint32_t GetBodyLength() const = 0;
	virtual void SetBodyLength(uint32_t nLength) = 0;

	virtual uint32_t GetTimeTamp() const = 0;

	virtual void SetTimeTamp(uint32_t nTimeTamp) = 0;

	virtual uint32_t GetReserverd() const = 0;

	virtual void SetReserverd(uint32_t nReserverd) = 0;

	int64_t NF_HTONLL(int64_t nData)
	{
#if NF_PLATFORM == NF_PLATFORM_WIN
		//#ifdef _MSC_VER
		return htonll(nData);
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_APPLE_IOS
		//#elseifdef __APPLE_CC__
		return OSSwapHostToBigInt64(nData);
#else
		return htobe64(nData);
#endif
	}

	int64_t NF_NTOHLL(int64_t nData)
	{
#if NF_PLATFORM == NF_PLATFORM_WIN
		//#ifdef _MSC_VER
		return ntohll(nData);
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_APPLE_IOS
		//#elseifdef __APPLE__
		return OSSwapBigToHostInt64(nData);
#elif NF_PLATFORM == NF_PLATFORM_ANDROID
		return betoh64(nData);
#else
		return be64toh(nData);
#endif
	}

	int32_t NF_HTONL(int32_t nData)
	{
#if NF_PLATFORM == NF_PLATFORM_WIN
		//#ifdef _MSC_VER
		return htonl(nData);
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_APPLE_IOS
		//#elseifdef __APPLE__
		return OSSwapHostToBigInt32(nData);
#else
		return htobe32(nData);
#endif
	}

	int32_t NF_NTOHL(int32_t nData)
	{
#if NF_PLATFORM == NF_PLATFORM_WIN
		//#ifdef _MSC_VER
		return ntohl(nData);
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_APPLE_IOS
		//#elseifdef __APPLE__
		return OSSwapBigToHostInt32(nData);
#elif NF_PLATFORM == NF_PLATFORM_ANDROID
		return betoh32(nData);
#else
		return be32toh(nData);
#endif
	}

	int16_t NF_HTONS(int16_t nData)
	{
#if NF_PLATFORM == NF_PLATFORM_WIN
		//#ifdef _MSC_VER
		return htons(nData);
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_APPLE_IOS
		//#elseifdef __APPLE__
		return OSSwapHostToBigInt16(nData);
#else
		return htobe16(nData);
#endif
	}

	int16_t NF_NTOHS(int16_t nData)
	{
#if NF_PLATFORM == NF_PLATFORM_WIN
		//#ifdef _MSC_VER
		return ntohs(nData);
#elif NF_PLATFORM == NF_PLATFORM_APPLE || NF_PLATFORM == NF_PLATFORM_APPLE_IOS
		//#elseifdef __APPLE__
		return OSSwapBigToHostInt16(nData);
#elif NF_PLATFORM == NF_PLATFORM_ANDROID
		return betoh16(nData);
#else
		return be16toh(nData);
#endif
	}
};
